//Taking an example from the last lab and putting in dead statements to test dead code elimination
#include <stdio.h>
#define WriteLine() printf("\n");
#define WriteLong(x) printf(" %lld", (long)x);
#define ReadLong(a) if (fscanf(stdin, "%lld", &a) != 1) a = 0;
#define long long long

long z[10];
long merge[10];

void mergesort(long i, long j){
	long temp;
	long ret;
	long a, b;
	long q, c1, c2, k;
	ret = 0;

	if((j - i) <= 1){
		ret = 1;
		//return
	}
	else{
		if((j - i) == 2){
			if(z[i] > z[j - 1]){
				temp = z[i];
				z[i] = z[j - 1];
				z[j - 1] = temp;
			}
			ret = 1;
			//return;
		}
	}
	if(ret == 0){
		q = (i + j)/2;
		mergesort(i,q);
		mergesort(q,j);
		c1 = i;
		c2 = q;
		k = i;
		while(((q-c1) + (j - c2)) > 0){
			if((q - c1) == 0){
				while(c2 < j){
					merge[k] = z[c2];
					c2 = c2 + 1;
					k = k + 1;
				}
			}
			else{
				if((j - c2) == 0){
					while(c1 < q){
						merge[k] = z[c1];
						c1 = c1 + 1;
						k = k + 1;
					}
				}
			}
	
			if(k < j){
				if(z[c1] <= z[c2]){
					merge[k] = z[c1];
					c1 = c1 + 1;
				}
				else{
					merge[k] = z[c2];
					c2 = c2 + 1;
				}
			}
			k = k + 1;
		}
	
		while(i < j){
			z[i] = merge[i];
			i = i + 1;
		}
	}
	//return;
}

void main(){
	z[0] = 5;
	z[1] = 2;
	z[2] = 8;
	z[3] = 6;
	z[4] = 4;
	z[5] = 3;
	z[6] = 10;
	z[7] = 7;
	z[8] = 9;
	z[9] = 1;

	mergesort(0, 10);

	WriteLong(z[0]);
	WriteLine();
	WriteLong(z[1]);
	WriteLine();
	WriteLong(z[2]);
	WriteLine();
	WriteLong(z[3]);
	WriteLine();
	WriteLong(z[4]);
	WriteLine();
	WriteLong(z[5]);
	WriteLine();
	WriteLong(z[6]);
	WriteLine();
	WriteLong(z[7]);
	WriteLine();
	WriteLong(z[8]);
	WriteLine();
	WriteLong(z[9]);
	WriteLine();
}

/* Expected output:
1
2
3
4
5
6
7
8
9
10
*/
